//
//  BCBarButtonItem.swift
//  Blockfolio
//
//  Created by Maybe on 09/05/2021.
//

import UIKit

class BCBarButtonItem: UIBarButtonItem {

}

extension UIBarButtonItem {
    
    /**
     创建只带文字的item
     
     - parameter title:  标题
     - parameter target: 监听方法对象
     - parameter action: 方法选择器
     
     - returns: barButtonItem
     */
    class func leftItem(_ title: String, size: CGSize = CGSize(width: 80, height: 44), normalColor: UIColor = Color_Title, disabledColor: UIColor = UIColor(white: 0.7, alpha: 1), target: AnyObject, action: Selector) -> UIBarButtonItem {
        let itemButton = UIButton(type: .custom)
        itemButton.contentHorizontalAlignment = .left
        itemButton.setTitle(title, for: .normal)
        itemButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        itemButton.setTitleColor(normalColor, for: .normal)
        itemButton.setTitleColor(disabledColor, for: .disabled)
        itemButton.addTarget(target, action: action, for: .touchUpInside)
        itemButton.frame = CGRect(origin: CGPoint.zero, size: size)
        return UIBarButtonItem(customView: itemButton)
    }
    
    /**
     创建只带文字的item
     
     - parameter title:  标题
     - parameter target: 监听方法对象
     - parameter action: 方法选择器
     
     - returns: barButtonItem
     */
    class func rightItem(_ title: String, size: CGSize = CGSize(width: 80, height: 44), normalColor: UIColor = Color_Title, disabledColor: UIColor = UIColor(white: 0.7, alpha: 1), target: AnyObject, action: Selector) -> UIBarButtonItem {
        let itemButton = UIButton(type: .custom)
        itemButton.contentHorizontalAlignment = .right
        itemButton.setTitle(title, for: .normal)
        itemButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        itemButton.setTitleColor(normalColor, for: .normal)
        itemButton.setTitleColor(disabledColor, for: .disabled)
        itemButton.addTarget(target, action: action, for: .touchUpInside)
        itemButton.frame = CGRect(origin: CGPoint.zero, size: size)
        return UIBarButtonItem(customView: itemButton)
    }
    
    /**
     快速创建一个图标barButtonItem 左边
     
     - parameter normalImage:      默认图片名
     - parameter highlightedImage: 高亮图片名
     - parameter target:           监听方法对象
     - parameter action:           方法选择器
     
     - returns: barButtonItem
     */
    class func leftItem(_ normalImage: String, highlightedImage: String, size: CGSize = CGSize(width: 80, height: 44), target: AnyObject, action: Selector) -> UIBarButtonItem {
        let itemButton = UIButton(type: .custom)
        itemButton.contentHorizontalAlignment = .left
        itemButton.setImage(UIImage(named: normalImage), for: .normal)
        itemButton.setImage(UIImage(named: highlightedImage), for: .highlighted)
        itemButton.addTarget(target, action: action, for: .touchUpInside)
        itemButton.frame = CGRect(origin: CGPoint.zero, size: size)
        return UIBarButtonItem(customView: itemButton)
    }
    
    /**
     快速创建一个图标barButtonItem 右边
     
     - parameter normalImage:      默认图片名
     - parameter highlightedImage: 高亮图片名
     - parameter target:           监听方法对象
     - parameter action:           方法选择器
     
     - returns: barButtonItem
     */
    class func rightItem(_ normalImage: String, highlightedImage: String, size: CGSize = CGSize(width: 80, height: 44), target: AnyObject, action: Selector) -> UIBarButtonItem {
        let itemButton = UIButton(type: .custom)
        itemButton.contentHorizontalAlignment = .right
        itemButton.setImage(UIImage(named: normalImage), for: .normal)
        itemButton.setImage(UIImage(named: highlightedImage), for: .highlighted)
        itemButton.addTarget(target, action: action, for: .touchUpInside)
        itemButton.frame = CGRect(origin: CGPoint.zero, size: size)
        return UIBarButtonItem(customView: itemButton)
    }
    
}
